package com.neo.test.juc;

/**
 * @author Kisen
 * @email lqs0911@qq.com
 * @date 2023/3/7 22:36
 * @detail
 */
public class WaitNotifyDemo {

    static Object lock = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lock) {
                System.out.println(Thread.currentThread().getName() + " come in.");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 唤醒.");
            }
        }, "Thread A").start();

        new Thread(() -> {
            synchronized (lock) {
                lock.notify();
                System.out.println(Thread.currentThread().getName() + " 通知.");
            }
        }, "Thread B").start();
    }
}
